import flash.events.Event;
import flash.events.EventDispatcher;

class CircleModel extends AVerletModel
{
  private var _radius:Float;
  private var _type:String;
  public var Alpha:Float;
  public var Fading:Int;
  public var FadeRate:Int;
  public var invincible:Int;
  public var InvincibilityLength:Int;
  public var _maxTileSize:Int;
  public var exit:Bool;

  private var _mapRow:Int;
  private var _mapColumn:Int;

  public function new
    (type:String,?radius:Float = 30, ?color:Int = 0x999999,?inFadeRate:Int = 100)
  {
    super();
    _type = type;
    this.radius = radius;
    this.color = color;
    FadeRate = inFadeRate;
    Fading = 0;
    Alpha = 1;
    InvincibilityLength = 100;
    _maxTileSize = Constants.MAX_TILE_SIZE;
    exit = false;
  }

  public override function update()
  {
    super.update();
    if(Fading > 0)
      {
      Fading++;
      Alpha=1-(Fading/FadeRate);
      if(Alpha < 0)
	{Alpha = 0;}
      }
    if(invincible != 0)
      {invincible++;}
    if(invincible > InvincibilityLength)
      {
      invincible = 0;
      }
    visible = (invincible % 4 != 1);
    
    
  }

  public function getType()
  {
    return _type;
  }
  //radius
  public var radius(getRadius,setRadius):Float;
  public function getRadius():Float
  {
    return _radius;
  }
  public function setRadius(value:Float):Float
  {
    _radius = value;
    this.width = Std.int(radius * 2);
    this.height = Std.int(radius * 2);
    return _radius;
  }

  //Rows and column that the object occupies
  public var mapColumn(get_mapColumn,set_mapColumn):Int;
  public function get_mapColumn():Int
  {
     _mapColumn = Math.floor((xPos) / _maxTileSize);
     return _mapColumn;
  }
  public function set_mapColumn(value:Int):Int
  {
     _mapColumn = value;
     return _mapColumn;
  }

  public var mapRow(get_mapRow,set_mapRow):Int;
  public function get_mapRow():Int
  {
     _mapRow = Math.floor((yPos) / _maxTileSize);
     return _mapRow;
  }
  public function set_mapRow(value:Int):Int
  {
     _mapRow = value;
     return _mapRow;
  }
 //Top, bottom, left and right sides
  public var top(get_top,null):Int;
  public function get_top():Int
  {
     var top:Int = Math.floor( (yPos- height/2) / _maxTileSize);
     return top;
  }
  public var bottom(get_bottom,null):Int;
  public function get_bottom():Int
  {
     var bottom:Int = Math.floor((yPos + height/2) / _maxTileSize);
     return bottom;
  }
  public var left(get_left,null):Int;
  public function get_left():Int
  {
    
     var left:Int = Math.floor((xPos-width/2) / _maxTileSize);
     return left;
  }
  public var right(get_right,null):Int;
  public function get_right():Int
  {
     var right:Int = Math.floor((xPos + width/2) / _maxTileSize);
     return right;
  }
  public var centerX(get_centerX,null):Int;
  public function get_centerX():Int
  {
     var centerX:Int = Math.floor((xPos) / _maxTileSize);
     return centerX;
  }
  public var centerY(get_centerY,null):Int;
  public function get_centerY():Int
  {
     var centerY:Int = Math.floor((yPos) / _maxTileSize);
     return centerY;
  }
}